package com.itboye.jigongbao.activity

import android.content.Intent
import android.os.Handler
import android.view.View
import com.itboye.jigongbao.MainActivity
import com.itboye.jigongbao.R
import com.itboye.jigongbao.app.MyApplication
import com.itboye.jigongbao.base.BaseActivity
import com.itboye.jigongbao.bean.LoginInfo
import com.itboye.jigongbao.logincontroller.LoginController
import com.itboye.jigongbao.logincontroller.LoginedState
import com.itboye.jigongbao.logincontroller.UnLoginState
import com.itboye.jigongbao.utils.Const
import kotlinx.android.synthetic.main.activity_splash.*

class SplashActivity : BaseActivity() {
    override fun getLayoutId(): Int {
        return R.layout.activity_splash
    }

    override fun initData() {
        img_splash.setBackgroundResource(R.drawable.jigongbao_splash)
        Handler().postDelayed(object : Runnable {
            override fun run() {
                var loginInfo = MyApplication.instance!!.mACache!!.getAsObject(Const.LOGIN_INFO)
                if (loginInfo==null) {
                    LoginController.setLoginState(UnLoginState())
                    startActivity(Intent(this@SplashActivity, LoginActivity::class.java))
                }else{
                    MyApplication.instance!!.loginInfo=loginInfo as LoginInfo
                    LoginController.setLoginState(LoginedState())
                    startActivity(Intent(this@SplashActivity, MainActivity::class.java))
                }
//                var isLogin = SPUtils.get(this@SplashActivity, null, Const.HAS_LOGIN, false)
                finish()
            }

        }, 300)
    }

    override fun onClick(p0: View?) {

    }

}
